#include"queuesafesem.hpp"

#define THREADCOUNT 1

void* cons_thread(void* arg){
  QueueSafeSem* sq=(QueueSafeSem*)arg;
    int data=0;
  while(1){
    sq->Push(data);
    data++;
  }
}
void* prod_thread(void* arg){
  QueueSafeSem* sq=(QueueSafeSem*)arg;
  while(1){
    sq->Pop();
  }
}

int main(){
  QueueSafeSem* sq=new QueueSafeSem();
  if(sq==NULL){
    return 0;
  }
  pthread_t cons[THREADCOUNT],prod[THREADCOUNT];
  for(int i=0;i<THREADCOUNT;i++){
    int ret =pthread_create(&cons[i],NULL,cons_thread,(void*)sq);
    if(ret<0){
      perror("pthread_create");
      return 0;
    }
    ret =pthread_create(&cons[i],NULL,prod_thread,(void*)sq);
    if(ret<0){
      perror("pthread_create");
      return 0;
    }
  }
  for(int i=0;i<THREADCOUNT;i++){
    pthread_join(cons[i],NULL);
    pthread_join(prod[i],NULL);
  }
  return 0;
}
